**Tables for number of survey projects, countries and years non-missing for each variable used in the trends analysis paper
use "Trust_trends_rep.dta", clear

tabout study_all using N_study_all.xls, c(count year min year max year sum tag_study_allyear sum tag_study_allcountry) replace sum format(0) sort
tabout study_all if !missing(trust_parl) | !missing(trust_gov) | !missing(trust_polpar) using N_study_all_pol.xls, c(count year min year max year sum tag_study_allyear sum tag_study_allcountry) replace sum format(0) sort
tabout country using N_Country.xls, c(count year min year max year sum tag_countryyear sum tag_countrystudy_all) replace sum format(0) sort

tabout study_all using N_study_all_var.xls, c(count trust_parl count trust_gov count trust_polpar count trust_civil count trust_leg count trust_police) replace sum format(0) sort
tabout country using N_Country_var.xls, c(count trust_parl count trust_gov count trust_polpar count trust_civil count trust_leg count trust_police) replace sum format(0) sort
tabout year using N_Year_var.xls, c(count trust_parl count trust_gov count trust_polpar count trust_civil count trust_leg count trust_police) replace sum format(0) sort

tabout regpol6 using N_Region.xls, c(count trust_parl count trust_gov count trust_polpar count trust_civil count trust_leg count trust_police) replace sum format(0) sort

tabout country using N_Country_dem.xls, c(mean vdem_row_perc) replace sum format(2) sort

tabout q_scale_parl q_scale_gov q_scale_polpar q_scale_civil q_scale_leg q_scale_police using N_Scales.xls, replace format(2) oneway c(freq col)

tabout study_all if q_scale_parl==3 using N_Scales_parl_3.xls, replace format(2) oneway c(freq col)
tabout study_all if q_scale_parl==5 using N_Scales_parl_5.xls, replace format(2) oneway c(freq col)
tabout study_all if q_scale_parl==7 using N_Scales_parl_7.xls, replace format(2) oneway c(freq col)
tabout study_all if q_scale_parl==11 using N_Scales_parl_11.xls, replace format(2) oneway c(freq col)

**Versions of the data where trust measures with mid-points and without midpoints (use only 4-point scales here) are included in the same country-years, for tests of semantic equivalence for dichotomization
use "Trust_trends_rep.dta", clear
tab q_scale_parl,gen(scale_parl_)

by country year, sort: egen scale_parl_2_tag=max(scale_parl_1)
by country year, sort: egen scale_parl_3_tag=max(scale_parl_2)
by country year, sort: egen scale_parl_4_tag=max(scale_parl_3)
by country year, sort: egen scale_parl_5_tag=max(scale_parl_4)
by country year, sort: egen scale_parl_7_tag=max(scale_parl_5)
by country year, sort: egen scale_parl_10_tag=max(scale_parl_6)
by country year, sort: egen scale_parl_11_tag=max(scale_parl_7)

cap gen trust_parl_midmis=trust_parl
replace trust_parl_midmis=. if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10

replace trust_parl=. if q_scale_parl==3 | q_scale_parl==5 | q_scale_parl==7 | q_scale_parl==9 | q_scale_parl==11 

replace trust_parl_midlow=. if !missing(trust_parl)
replace trust_parl_midhi=. if !missing(trust_parl)

save "Trust_trends_midpoints.dta", replace

*For 3-point measures
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==3
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_3_tag==1
collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints3.dta", replace
*Making the mid-points missing has the strongest correlation with results in the same country-years from 4-point measures: 0.87 vs. 0.85 and 0.86 Pearson's R for the versions classifying them as lack of trust and trust, respectively

*For 5-point measures in the ISSP
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==5
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_5_tag==1

gen ISSP_tag=0
replace ISSP_tag=1 if study=="ISSP"
by country year, sort: egen ISSP_cytag=max(ISSP_tag)

collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi ISSP_cytag (first) study_all, by(country year)
keep if ISSP_cytag==1

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints5.dta", replace

*All other than the ISSP
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==5
keep if study!="ISSP"
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_5_tag==1
collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints5_noISSP.dta", replace

*For 7-point measures
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==7
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_7_tag==1
collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints7.dta", replace

*Without the AmericasBarometer
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==7
keep if study_all!="AmericasBarometer"
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_7_tag==1
collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints7_noLAPOP.dta", replace

*For 11-point measures
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==11
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_11_tag==1
collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints11.dta", replace

*For 11-point measures - only observations including the ESS
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==11
keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_11_tag==1

gen ESS_tag=0
replace ESS_tag=1 if study=="ESS"
by country year, sort: egen ESS_cytag=max(ESS_tag)

collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints11_ESS.dta", replace

*For 11-point measures - without the ESS
use "Trust_trends_midpoints.dta", clear
keep if q_scale_parl==2 | q_scale_parl==4 | q_scale_parl==10 | q_scale_parl==11
keep if study!="ESS"

keep if (scale_parl_2_tag==1 | scale_parl_4_tag==1 | scale_parl_10_tag==1) & scale_parl_11_tag==1

collapse trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi (first) study_all, by(country year)

cor trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
mean trust_parl trust_parl_midmis trust_parl_midlow trust_parl_midhi
save "Trust_trends_midpoints11_noESS.dta", replace
